package cn.hotel.controller.worker;

import cn.hotel.response.ResponseTool;
import cn.hotel.response.Result;
import cn.hotel.service.CheckInService;
import cn.hotel.service.CleanerService;
import cn.hotel.service.RoomTypeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.relational.core.sql.In;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;

@RestController
@RequestMapping(value = "/op/checkIn")
@Slf4j
public class OpCheckInController {

    @Resource
    private CheckInService checkInService;

    @Resource
    private RoomTypeService roomTypeService;

    @Resource
    private CleanerService cleanerService;

    @PostMapping("/in")
    public Result checkIn(Integer orderId) {
        log.info("获取的orderId信息{}" , orderId);
        int i = checkInService.updateStatus(orderId);
        return ResponseTool.success();
    }

    @PostMapping("/over")
    public Result checkOver(Integer orderId , Integer typeId) {
        log.info("获取的orderId信息{}" , orderId);
        Timer timer = new Timer();

        int count = cleanerService.getCount();
        log.info("随机分配的保洁员id:{}" , count);
        int i2 = cleanerService.updateNum(count , "+1");

        TimerTask task = new TimerTask() {
            @Override
            public void run() {
                int i = checkInService.updateStatus2(orderId);
                int i1 = roomTypeService.updateRoomRest(typeId, "+1");
                int a = cleanerService.updateNum(count, "-1");
            }
        };
        timer.schedule(task, 10000);
        return ResponseTool.success();

    }
}
